package org.agilelang.editor.tool;

/*
 AgileLang - A fourth generation language(http://www.agilelang.org).

 Copyright (C) 2013 Roderick Cusirramos (roderick20@hotmail.com)

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import javax.swing.*;
import static org.agilelang.editor.tool.I18n._;

public class Util {
    
    static public JMenuItem createMenuItem(String titulo, String imagen) {
        JMenuItem MenuFile;
        if (imagen.equals("")) {
            MenuFile = new JMenuItem(_(titulo));
        } else {
            MenuFile = new JMenuItem(_(titulo), new ImageIcon(getIconImage("org/agilelang/editor/resources/img16/" + imagen)));
        }
        return MenuFile;
    }
    
    static public Image getIconImage(String urlimagen) {
        Image retValue = Toolkit.getDefaultToolkit().
                getImage(ClassLoader.getSystemResource(urlimagen));
        return retValue;
    }
    
    static public JMenu createMenu(String titulo) {
        return new JMenu(_(titulo));
    }
    
    static public JMenu createMenuIcon(String imagen) {
        JMenu MenuFile;
        
            
            MenuFile = new JMenu();
            MenuFile.setIcon(new ImageIcon(getIconImage("org/agilelang/editor/resources/img22/" + imagen)));
                    
        return MenuFile;
    }

    static public JMenuItem createMenuItem(String titulo) {
        return new JMenuItem(_(titulo));
    }

    //--------------------------------------------------------------------------
    static public JMenuItem createMenuItem(String titulo, String imagen, String tecla) {
        //imagen 16x16
        JMenuItem MenuFile;
        if (imagen.equals("")) {
            MenuFile = new JMenuItem(titulo);
        } else {
            MenuFile = new JMenuItem(titulo, new ImageIcon(getIconImage("org/agilelang/editor/resources/img22/" + imagen)));
        }
        if(!tecla.equals("")){
            MenuFile.setAccelerator(KeyStroke.getKeyStroke(tecla));
        }
        return MenuFile;
    }
    
    static public JMenuItem createMenuItem(String titulo, String imagen, String tecla,ActionListener l) {
        //imagen 16x16
        JMenuItem MenuFile;
        if (imagen.equals("")) {
            MenuFile = new JMenuItem(titulo);
        } else {
            MenuFile = new JMenuItem(titulo, new ImageIcon(getIconImage("org/agilelang/editor/resources/img22/" + imagen)));
        }
        if(!tecla.equals("")){
            MenuFile.setAccelerator(KeyStroke.getKeyStroke(tecla));
        }
        MenuFile.addActionListener( l );
        return MenuFile;
    }
    
    
    
    static public JMenuItem createMenuItem(String titulo, String imagen,ActionListener l) {
        //imagen 16x16
        JMenuItem MenuFile;
        if (imagen.equals("")) {
            MenuFile = new JMenuItem(titulo);
        } else {
            MenuFile = new JMenuItem(titulo, new ImageIcon(getIconImage("org/agilelang/editor/resources/img22/" + imagen)));
        }      
        MenuFile.addActionListener( l );
        return MenuFile;
    }
    
    static public JButton createToolBarItem(String titulo, String imagen, ActionListener l){
        JButton button = new JButton(new ImageIcon(getIconImage("org/agilelang/editor/resources/img22/" + imagen)));
        button.setToolTipText(titulo);
        button.addActionListener(l);
        return button;
    }
    
    
}
